package com.szzg10.mina2.chapter9;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class ImageServer {

	public static final int PORT = 33789;
	
	public void start() throws IOException {
		
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		
		acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ImageCodecFactory(false)));
		
		acceptor.setHandler(new ImageServerHandler());
		
		acceptor.bind(new InetSocketAddress(PORT));
	}
	
}
